import {createI18n} from 'vue-i18n'
import viVn from './vi-vn'
import zhCn from './zh-cn'
import {Locale} from 'vant';
import vantZhLocale from 'vant/es/locale/lang/zh-CN';
import vantVivnLocale from './vantviVn';

const getCaption = (name) => {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return '';
}
const i18n = createI18n({
    locale: localStorage.getItem('locale') || 'vi_VN',
    messages: {
        zh_CN: {
            ...zhCn,
            ...vantZhLocale
        },
        vi_VN: {
            ...viVn,
            ...vantVivnLocale
        },
    },
});
if (localStorage.getItem('locale') === 'zh_CN' || getCaption('locale') === 'zh_CN') {
    Locale.use('zh_CN', vantZhLocale)
} else {
    Locale.use('vi_VN', vantVivnLocale)
}
export default i18n
